﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DBUtility;
using System.Data.OracleClient;
namespace OracleDAL.Sec
{
    /// <summary>
    /// 数据访问类ModifyNode。
    /// </summary>
    public class ModifyNode
    {
        public ModifyNode()
        { }
        #region  成员方法


        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string TOTABNAME, string TOCOLNAME, string FROMTABNAME, string FROMCOLNAME)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from sec_Modify_Node ");
            strSql.Append(" where TOTABNAME='" + TOTABNAME + "' and TOCOLNAME='" + TOCOLNAME + "' and FROMTABNAME='" + FROMTABNAME + "' and FROMCOLNAME='" + FROMCOLNAME + "' ");
            return OracleHelper.Exists(strSql.ToString());
        }
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from sec_Modify_Node where ");
            strSql.Append(strWhere);
            return OracleHelper.Exists(strSql.ToString());
        }
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(Model.Sec.ModifyNode model)
        {
            StringBuilder strSql = new StringBuilder();
            StringBuilder strSql1 = new StringBuilder();
            StringBuilder strSql2 = new StringBuilder();
            if (model.TOTABNAME != null)
            {
                strSql1.Append("TOTABNAME,");
                strSql2.Append("'" + model.TOTABNAME + "',");
            }
            if (model.TOCOLNAME != null)
            {
                strSql1.Append("TOCOLNAME,");
                strSql2.Append("'" + model.TOCOLNAME + "',");
            }
            if (model.FROMTABNAME != null)
            {
                strSql1.Append("FROMTABNAME,");
                strSql2.Append("'" + model.FROMTABNAME + "',");
            }
            if (model.FROMCOLNAME != null)
            {
                strSql1.Append("FROMCOLNAME,");
                strSql2.Append("'" + model.FROMCOLNAME + "',");
            }
            strSql.Append("insert into sec_Modify_Node (");
            strSql.Append(strSql1.ToString().Remove(strSql1.Length - 1));
            strSql.Append(")");
            strSql.Append(" values (");
            strSql.Append(strSql2.ToString().Remove(strSql2.Length - 1));
            strSql.Append(")");
            int row=OracleHelper.ExecuteSql(strSql.ToString());
            if (row > 0)
                return true;
            else return false;
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.Sec.ModifyNode model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update sec_Modify_Node set ");
            strSql.Append("TOTABNAME='" + model.TOTABNAME + "',");
            strSql.Append("TOCOLNAME='" + model.TOCOLNAME + "',");
            strSql.Append("FROMTABNAME='" + model.FROMTABNAME + "',");
            strSql.Append("FROMCOLNAME='" + model.FROMCOLNAME + "'");
            strSql.Append(" where TOTABNAME='" + model.TOTABNAME + "' and TOCOLNAME='" + model.TOCOLNAME + "' and FROMTABNAME='" + model.FROMTABNAME + "' and FROMCOLNAME='" + model.FROMCOLNAME + "' ");
            int row=OracleHelper.ExecuteSql(strSql.ToString());
            if (row > 0)
            {
                return true;

            }
            else return false;
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(string TOTABNAME, string TOCOLNAME, string FROMTABNAME, string FROMCOLNAME)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete sec_Modify_Node  ");
            strSql.Append(" where TOTABNAME='" + TOTABNAME + "' and TOCOLNAME='" + TOCOLNAME + "' and FROMTABNAME='" + FROMTABNAME + "' and FROMCOLNAME='" + FROMCOLNAME + "' ");
            int row=OracleHelper.ExecuteSql(strSql.ToString());
            if (row > 0)
                return true;
            else return false;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="strWhere"></param>
        /// <returns></returns>
        public bool Delete(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete sec_Modify_Node  ");
            strSql.Append(strWhere);
            int row = OracleHelper.ExecuteSql(strSql.ToString());
            if (row > 0)
                return true;
            else 
                return false;

        }

        public Model.Sec.ModifyNode GetModel(string StrWhere)
        {
            bool flag = false;
            Model.Sec.ModifyNode modify = new Model.Sec.ModifyNode();
            StringBuilder sql = new StringBuilder();
            sql.Append("select * from sec_modify where ");
            sql.Append(StrWhere);
            OracleDataReader dr = OracleHelper.ExecuteReader(sql.ToString());
            while (dr.Read())
            {
                flag = true;
               
                modify.TOTABNAME = dr["TOTABNAME"].ToString();
                modify.TOCOLNAME = dr["TOCOLNAME"].ToString();
                modify.FROMTABNAME = dr["FROMTABNAME"].ToString();
                modify.FROMCOLNAME = dr["FROMCOLNAME"].ToString();
            }
            dr.Close();
            if (flag)
                return modify;
            else
                return null;
        }
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.Sec.ModifyNode GetModel(string TOTABNAME, string TOCOLNAME, string FROMTABNAME, string FROMCOLNAME)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  ");
            strSql.Append(" TOTABNAME,TOCOLNAME,FROMTABNAME,FROMCOLNAME ");
            strSql.Append(" from sec_Modify_Node  ");
            strSql.Append(" where TOTABNAME='" + TOTABNAME + "' and TOCOLNAME='" + TOCOLNAME + "' and FROMTABNAME='" + FROMTABNAME + "' and FROMCOLNAME='" + FROMCOLNAME + "' ");
            Model.Sec.ModifyNode model = new Model.Sec.ModifyNode();
            DataSet ds = OracleHelper.Query(strSql.ToString());
            if (ds.Tables[0].Rows.Count > 0)
            {
                model.TOTABNAME = ds.Tables[0].Rows[0]["TOTABNAME"].ToString();
                model.TOCOLNAME = ds.Tables[0].Rows[0]["TOCOLNAME"].ToString();
                model.FROMTABNAME = ds.Tables[0].Rows[0]["FROMTABNAME"].ToString();
                model.FROMCOLNAME = ds.Tables[0].Rows[0]["FROMCOLNAME"].ToString();
                return model;
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select TOTABNAME,TOCOLNAME,FROMTABNAME,FROMCOLNAME ");
            strSql.Append(" FROM sec_Modify_Node  ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return OracleHelper.Query(strSql.ToString());
        }
        public bool ChangeNodeISN(string tableName, string toColname, string OldNodeISN, string NewNodeISN)
        {
            string sql = "update " + tableName + "set " + toColname + "='" + NewNodeISN + "' where " + toColname + "='" + OldNodeISN + "'";
            int rows = OracleHelper.ExecuteSql(sql);
            if (rows > 0)
                return true;
            else
                return false;
        }
        /*
        */

        #endregion  成员方法
    }
}
